﻿using Anke.SHManage.MSSQLDAL.TJDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TJ_GRQFModeWebForm : System.Web.UI.Page
    {
        private string reportName; 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();

        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;
            BindReportDataSource();
        }

        protected void BindReportDataSource()
        {
            DateTime beginTime = Convert.ToDateTime(this.StartDate.Text);
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            string stationID = (this.Station.Text).ToString();
            string doctor = Convert.ToString(this.Doctor.Text);
            string driver = Convert.ToString(this.Driver.Text);
            string stretcherBearers = Convert.ToString(this.StretcherBearers.Text);
            //string doctorworkcode = Convert.ToString(this.DoctorWorkCode.Text);
            //string driverworkcode = Convert.ToString(this.DriverWorkCode.Text);
            //string stretcherBearersworkcode = Convert.ToString(this.StretcherBearersWorkCode.Text);
            string start1 = beginTime.ToString();
            string end1 = endTime.ToString();
            //string type1 = (this.Type.Value).ToString();

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("startTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("endTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
            TJDAL dal = new TJDAL();

            switch (reportName)
            {
                case "TJ_GRQFCDWS.rdlc":
                    this.Page.Title = "急救中心个人业务款欠费流水表(车到未送)";
                    DataTable dt1 = dal.Get_TJ_GRQFCDWS(beginTime, endTime, stationID, driver, doctor, stretcherBearers);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_GRQFCDWS", dt1));
                    break;
                case "TJ_GRQFSDYY.rdlc":
                    this.Page.Title = "急救中心个人业务款欠费流水表(送到医院)";
                    DataTable dt2 = dal.Get_TJ_GRQFSDYY(beginTime, endTime, stationID, driver, doctor, stretcherBearers);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_GRQFSDYY", dt2));
                    break;
                case "TJ_GRQFWKXY.rdlc":
                    this.Page.Title = "急救中心个人业务款欠费流水表(五康协议)";
                    DataTable dt3 = dal.Get_TJ_GRQFWKXY(beginTime, endTime, stationID, driver, doctor, stretcherBearers);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_GRQFWKXY", dt3));
                    break;
                case "TJ_GRQFZSXY.rdlc": //中山协议 add2024-08-29 plq
                    this.Page.Title = "急救中心个人业务款欠费流水表(中山协议)";
                    DataTable dt4 = dal.Get_TJ_GRQFZSXY(beginTime, endTime, stationID, driver, doctor, stretcherBearers);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_GRQFZSXY", dt4));
                    break;

                default:
                    break;
            }

            this.ReportViewer1.LocalReport.Refresh();
        }
    }
}